#!/bin/bash
[% c("var/set_default_env") -%]
distdir="/var/tmp/dist/[% project %]"
[% c("var/set_PTDIR_DOCSDIR") -%]
mkdir -p $PTDIR $DOCSDIR
[% IF c("var/windows") -%]
  [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
[% END -%]
tar -C $distdir -xf $rootdir/[% c('input_files_by_name/libfte') %]
mkdir -p /var/tmp/build
tar -C /var/tmp/build -xf $rootdir/[% project %]-[% c('version') %].tar.gz
cd /var/tmp/build/[% project %]-[% c('version') %]
[% IF c("var/windows") -%]
  pydir="$distdir/python"
  export PYTHONPATH="$(wine winepath -w $pydir)\\Lib\\site-packages"
  $PYTHON setup_tbb.py py2exe
  py2exe_zip_timestomp dist/fteproxy.zip
  cp -an dist/{*.pyd,*.exe,*.zip} $PTDIR/
  mkdir -p $PTDIR/fteproxy
  cp -a fteproxy/VERSION $PTDIR/fteproxy
  mkdir -p $PTDIR/fteproxy/defs
  cp -a fteproxy/defs/*.json $PTDIR/fteproxy/defs
  rm -Rf $pydir
[% ELSE -%]
  cp -a bin/fteproxy $PTDIR/fteproxy.bin
  cp -ra fteproxy $PTDIR/
[% END -%]
cp -a {COPYING,README.md} $DOCSDIR/
cd $distdir
[% c('tar', {
        tar_src => [ '.' ],
        tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
    }) %]
